#include <stdio.h>
#include <stdlib.h>

/********************************************************************************
 * Problema da disciplina de Estrutura de Dados e Complexidade de Algoritmos da *
 * Pos Graduacao do Periodo 2011.1                                              *
 *                                                                              *
 * @see https://br.spoj.pl/problems/PEDAGIO/                                    *
 * @author Elenilson Vieira - 111100371 - elenilson[at]elenilsonvieira.com      *
 * @since 12 de junho de 2011                                                    *
 ********************************************************************************/
int main(int argc, char** argv) {

    int testNumber = 1;

    /*** Pega sequencia de comandos e executa ***/
    int citiesAmount = 0;
    int roadsAmount = 0;
    int jucaCity = 0;
    int maxToll = 0;
    while (scanf("%d %d %d %d", &citiesAmount, &roadsAmount, &jucaCity, &maxToll) 
            && citiesAmount != 0 && roadsAmount != 0 && jucaCity != 0 && maxToll != 0) {

        int citiesToVisit[citiesAmount];
        int graph[citiesAmount][citiesAmount];

        /*** Inicia os arrays ***/
        int i = 0;
        int j = 0;
        int levelCities[citiesAmount];
        for(i = 0; i < citiesAmount; i++){
            citiesToVisit[i] = 0;
            levelCities[i] = 0;
            for(j = 0; j < citiesAmount; j++)
                graph[i][j] = 0;
        }

        /*** Ler as rodovias ***/
        for (i= 0; i < roadsAmount; i++) {
            int x = 0;
            int y = 0;
            scanf("%d %d", &x, &y);

            graph[x - 1][y - 1] = 1;
            graph[y - 1][x - 1] = 1;
        }


        levelCities[jucaCity - 1] = 1;

        /*** Bota a cidade de juquinha como primeiro nivel a ser varrido ***/
        int nextLevelCities[citiesAmount];
        for (j = 0; j < citiesAmount; j++)
            nextLevelCities[j] = 0;

        for (i= 0; i < maxToll; i++) {

            int levelCity = 0;
            for (levelCity = 0; levelCity < citiesAmount; levelCity++) {
                /*** Se for para verificar as rotas dessa cidade, ou seja, to no nivel dela ***/
                if(levelCities[levelCity]){
                    /*** Vejo as rotas da cidade ***/
                    for (j= 0; j < citiesAmount; j++) {
                        /***
                         * Se tem uma rota para a cidade de indice j, adiciona j
                         * no proximo nivel e j como sendo uma cidade a ser visitada
                         ***/
                        if(graph[levelCity][j] && j + 1 != jucaCity){
                            citiesToVisit[j] = 1;
                            nextLevelCities[j] = 1;
                        }
                    }
                }
            }

            /*** Copia o nextLevel para o levelAtual e limpa o nextLevel ***/
            for(j = 0; j < citiesAmount; j++){
                levelCities[j] = nextLevelCities[j];
                nextLevelCities[j] = 0;
            }
        }

        /*** Faz as impressoes ***/
        int isFirst = 1;
        for (i= 0; i < citiesAmount; i++) {
            if(citiesToVisit[i]){
                if(isFirst){
                    if(testNumber == 1)
                        printf("Teste %d\n%d", testNumber++, i + 1);
                    else
                        printf("\nTeste %d\n%d", testNumber++, i + 1);
                    isFirst = 0;
                }
                else 
                    printf(" %d", i + 1);
            }
        }
        
        printf("\n");
    }

    return (EXIT_SUCCESS);
}

